package com.sline.file;

import java.io.File;
import java.io.IOException;

public class Demo4_FileMethod {
    public static void main(String[] args) throws IOException {
        File dir = new File("dir1");
        System.out.println(dir.mkdir());

        File file = new File("abc");
        System.out.println(file.createNewFile());

        demo1();
        /*
        * exists: 判断文件是否存在
        * canRead: 判断文件是否可读*/


        File file1 = new File("abc");
    }

    private static void demo1() {
    /*
    * isDirectory: 判断是否是文件夹
    * isFile: 判断是否是文件
    * exists: 判断文件是否存在
    * canRead: 判断文件/文件夹是否可读
    * canWrite: 判断文件/文件夹是否可写
    * isHidden: 判断文件/文件夹是否隐藏
    * */
        File dir1 = new File("dir1");
        System.out.println("dir1.isDirectory: " + dir1.isDirectory());
        System.out.println("dir1.isFile: " + dir1.isFile());
        System.out.println("dir1.exists: " + dir1.exists());
        dir1.setReadable(false);
        System.out.println("dir1.canRead: " + dir1.canRead());
        dir1.setWritable(true);
        System.out.println("dir1.canWrite: " + dir1.canWrite());
        System.out.println("dir1.isHidden: " + dir1.isHidden());

        System.out.println("-------------------------");

        File file1 = new File("abc");
        System.out.println("file1.isDirectory: " + file1.isDirectory());
        System.out.println("file1.isFile: " + file1.isFile());
        System.out.println("file1.exists: " + file1.exists());
        file1.setReadable(true);
        System.out.println("file1.canRead: " + file1.canRead());
        file1.setWritable(false);
        System.out.println("file1.canWrite: " + file1.canWrite());
        System.out.println("file1.isHidden: " + file1.isHidden());
    }
}
